<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
<script>
// async修饰的函数promise
// promise + 停下来

function *gen() {
  const a = yield new Promise((resolve, reject) => {
    resolve(1)
  })
  // console.log(1)
  console.log(a)
  const b = yield new Promise((resolve, reject) => {
    resolve('b')
  })
  // console.log(1)
}

const it = gen()
const it1 = it.next()

// react 中间件 redux-saga
it1.value.then(res => {
  console.log(res)
  const it2 = it.next(res)
  console.log(it2)

  it2.value.then(res => {
    const it3 = it.next(res)
    const it4 = it.next(res)
    console.log(it4)
  })
})
// console.log(it1)
// async function get() {
//   const res = await new Promise(((resolve, reject) => {
//     setTimeout(() => {
//         // resolve(1)
//     }, 1000)
//   } ))
//   console.log(1)
//   const res1 = await new Promise(((resolve, reject) => {
//     setTimeout(() => {
//       resolve(1)
//     }, 1000)
//   } ))
//   // console.log(res)
//   return res
// }
//
// get().then(res => {
//   console.log(res)
// })
// // console.log(res)
</script>
</body>
</html>
